using System.Collections.Generic;
using System.Xml.Linq;

namespace WB.Mvc.Forms.Widgets
{
	public class CheckBox : Widget
	{
		/// <summary>
		/// Creates an instance of <see cref="CheckBox"/>.
		/// </summary>
		public CheckBox(string name) : this(name, AttributeDictionaryBuilder.New().Add("value", string.Empty).ToDictionary())
		{
		}

		/// <summary>
		/// Creates an instance of <see cref="CheckBox"/>.
		/// </summary>
		public CheckBox(string name, IDictionary<string, object> attributes) : base(name, attributes)
		{
			if (!attributes.ContainsKey("value"))
				attributes.Add("value", string.Empty);

			attributes.Add("type", "checkbox");
		}

		/// <summary>
		/// Returns the HTML string that corresponds to the widget.
		/// </summary>
		public override string ToHtml()
		{
			XElement ele = new XElement("input");
			foreach (var attrib in Attributes)
				ele.Add(new XAttribute(attrib.Key, attrib.Value));

			return ele.ToString();
		}
	}
}